package com.lhhu.demo.service.impl;

import com.lhhu.demo.bean.BookClassify;
import com.lhhu.demo.mapper.ClassifyMapper;
import com.lhhu.demo.service.ClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @Auther 虎
 * @Data 2021/3/10 12:52
 * @Version 1.0
 */
@Service
public class ClassifyServiceImpl implements ClassifyService {
    @Autowired
    private ClassifyMapper classifyMapper;

    @Override
    public List<BookClassify> getAllBookClassify() {
        return classifyMapper.getAllBookClassify();
    }

    @Override
    public int addOneBookClassify(String classify) {
        BookClassify bookClassify = new BookClassify();
        Date date = new Date(System.currentTimeMillis());
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMddHHmmss");
        int random = (int)(Math.random()*10);
        String classifyId ='2'+ dateFormat.format(date) + random;
        bookClassify.setBookClassifyId(classifyId);
        bookClassify.setBookClassify(classify);
        return classifyMapper.addOneBookClassify(bookClassify);
    }

    @Override
    public String getOneBookClassifyById(String bookClassifyId) {
        return classifyMapper.getOneBookClassifyById(bookClassifyId);
    }
}
